/// @tags: 2-SAT
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

namespace BlueQuantum {

int constexpr N = 5e4 + 3, M = 1e5 + 3, BN = 10000;

int n, m, T;
int typ[M], t[M], x[M], y[M], sizsum[M], fA[N], fD[N], ans[N];
bool vis[M * 3], mustdie[N];
bitset<BN> dp[M * 3], cur;
vector<int> g[M * 3];
vector<int> vec[N];

inline int alive(int i, int j) { return sizsum[i - 1] + j + 1; }

inline int dead(int i, int j) { return sizsum[i - 1] + j + 1 + sizsum[n]; }

inline void add(int u, int v) { g[u].push_back(v); }

void dfs(int u) {
  if (vis[u]) return;
  vis[u] = true;
  for (auto v : g[u]) dfs(v), dp[u] |= dp[v];
}

void clear(int u) {
  if (vis[u]) return;
  vis[u] = true;
  dp[u].reset();
  for (auto v : g[u]) clear(v);
}

inline int main() {
  cin >> T >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> typ[i] >> t[i] >> x[i] >> y[i];
    vec[x[i]].push_back(t[i]);
  }
  for (int i = 1; i <= n; ++i) {
    vec[i].push_back(T + 1);
    sort(vec[i].begin(), vec[i].end());
  }
  for (int i = 1; i <= n; ++i) sizsum[i] = sizsum[i - 1] + vec[i].size();
  for (int i = 1; i <= n; ++i) {
    int siz = vec[i].size();
    for (int j = 1; j < siz; ++j) add(alive(i, j), alive(i, j - 1));
    for (int j = 0; j < siz - 1; ++j) add(dead(i, j), dead(i, j + 1));
  }
  for (int i = 1; i <= m; ++i) {
    int xj = lower_bound(vec[x[i]].begin(), vec[x[i]].end(), t[i]) - vec[x[i]].begin();
    int yj = lower_bound(vec[y[i]].begin(), vec[y[i]].end(), t[i] + (!typ[i])) -
             vec[y[i]].begin();
    if (!typ[i]) {
      add(dead(x[i], xj), dead(y[i], yj));
      add(alive(y[i], yj), alive(x[i], xj));
    } else {
      add(alive(x[i], xj), dead(y[i], yj));
      add(alive(y[i], yj), dead(x[i], xj));
    }
  }
  for (int i = 1; i <= n; ++i) {
    fA[i] = alive(i, vec[i].size() - 1);
    fD[i] = dead(i, vec[i].size() - 1);
  }
  for (int l = 1, r; l <= n; l += BN) {
    r = min(l + BN - 1, n);
    for (int i = l; i <= r; ++i) dp[fD[i]][i - l] = true;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; ++i) dfs(fA[i]);
    cur.reset();
    for (int i = l; i <= r; ++i) {
      if (dp[fA[i]][i - l]) {
        mustdie[i] = cur[i - l] = true;
      }
    }
    for (int i = 1; i <= n; ++i) ans[i] += r - l + 1 - (cur | dp[fA[i]]).count();
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= n; ++i) clear(fA[i]);
  }
  for (int i = 1; i <= n; ++i) cout << (mustdie[i] ? 0 : ans[i] - 1) << ' ';
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P5332 [JSOI2019] 精准预测.in", "r", stdin);
  freopen("P5332 [JSOI2019] 精准预测.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
